<?php namespace system\model;
use houdunwang\model\Model;
use houdunwang\validate\Validate;

class User extends Model{
	//数据表
	protected $table = "user";

	//允许填充字段
	protected $allowFill = [ ];

	//禁止填充字段
	protected $denyFill = [ ];

	//自动验证
	protected $validate=[
//		['username','isnull ','不能为空',3 ],
//		['passw','isnull','密码不能为空',self::MUST_VALIDATE]
	];

	//自动完成
	protected $auto=[
		//['字段名','处理方法','方法类型',验证条件,验证时机]
	];

	//自动过滤
    protected $filter=[
        //[表单字段名,过滤条件,处理时间]
    ];

	//时间操作,需要表中存在created_at,updated_at字段
	protected $timestamps=false;

	public function login(){
		Validate::make( [
			[ 'code', 'isnull','验证码不为空', 3 ],
			['username','isnull','用户名不为空'],
			['password','isnull','密码不为空']
		]);
//		Validate::make( [
//			[ 'code', 'captcha', '验证码输入错误', 3 ]
//		] );

			//用户名密码不正确
			$username=$_POST['username'];
			$password=$_POST['password'];
			if(Db::table('user')->where('username',$username)->where('password',$password)->first()){
				Session::set('pid','id');
				return ['valite'=>1,'message'=>'登陆成功'];

			}else{
				return ['valite'=>0,'message'=>'用户名或者密码错误'];
			}
		}

}